package cn.afterturn.easypdf.util;

import org.apache.commons.lang3.StringUtils;

/**
 * 单词与汉语相关的的工具类
 */
public class WordsUtil {

    private static String ENGLISH_WORDS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

    /**
     * 剔除文字当中英文字母
     *
     * @param str
     * @return
     */
    public static String removeEnglish(String str) {
        str = str.replace("\r", "").replace("\n", "").replace("\r\n", "").replace(" ", "").trim();
        char[] chars = str.toCharArray();
        String data = "";
        for (int i = 0; i < chars.length; i++) {
            if (ENGLISH_WORDS.indexOf(chars[i]) == -1) {
                data += chars[i];
            }
        }
        return data;
    }

    public static String replaceAll(String str) {
        if (StringUtils.isEmpty(str)) {
            return str;
        }
        str = str.replace("\r", "").replace("\n", "").replace("\r\n", "");
        str = str.replace(" ", "");
        return str.replace(" ", "").trim();
    }
}
